home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7995 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  72 lines

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: New (but motivated) C user looking for help . . .
  5. Date: 28 Feb 1996 12:54:46 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4h2femINNrgi@anvil.ugrad.cs.ubc.ca>
  8. References: <4h10do$mqh@maureen.teleport.com> <4h1s9f$8nf@pyrrhus-f.hrz.tu-chemnitz.de>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <4h1s9f$8nf@pyrrhus-f.hrz.tu-chemnitz.de>,
  12. Hans Steffani <hfst@hrz.tu-chemnitz.de> wrote:
  13. >Input the adress as string.
  14. >Break it to substrings using "." as delimiter.
  15. >Convert the substrings without the "." to integer.
  16. >Use & and | to do or and and conjunction.
  17.  
  18. If you are doing internet programming with Berkeley sockets, functions that do
  19. this kind of thing are provided for you. Standard C functions they are not, but
  20. they do exist in environments where inet meets C.
  21.  
  22. hp-ux$ man inet
  23.  
  24. net(3N)                                                           inet(3N)
  25.  
  26.  NAME
  27.       inet_addr(), inet_network(), inet_ntoa(), inet_makeaddr(),
  28.       inet_lnaof(), inet_netof() - Internet address manipulation routines
  29.  
  30.  SYNOPSIS
  31.       #include <sys/socket.h>
  32.       #include <netinet/in.h>
  33.       #include <arpa/inet.h>
  34.  
  35.       unsigned long inet_addr(const char *cp);
  36.  
  37.       unsigned long inet_network(const char *cp);
  38.  
  39.       char *inet_ntoa(struct in_addr in);
  40.  
  41.       struct in_addr inet_makeaddr(int net, int lna);
  42.  
  43.       int inet_lnaof(struct in_addr in);
  44.  
  45.       int inet_netof(struct in_addr in);
  46.  
  47.  DESCRIPTION
  48.       inet_addr()           Interpret character strings representing numbers
  49.       inet_network()        expressed in the Internet standard ``dot''
  50.                             notation.
  51.  
  52.                             inet_addr() returns numbers suitable for use as
  53.                             Internet addresses.
  54.  
  55.                             inet_network() returns numbers suitable for use
  56.                             as Internet network numbers>
  57.  
  58.                             Return values can be assigned to a struct
  59.                             in_addr (defined in /usr/include/netinet/in.h)
  60.                             by using a technique similar to the following:
  61.  
  62.                                  struct in_addr addr;
  63.                                  char *cp;
  64.  
  65.                                  addr.s_addr = inet_addr(cp);
  66.  
  67. By the way, the above sentence is not correct. The unsigned long result of
  68. inet_addr() is _not_ being incorrectly assigned to a struct, but to an unsigned
  69. long element of the struct.
  70. -- 
  71.  
  72.